﻿using System;
using System.Collections.Generic;
using System.Linq;

using AddProductLib;

namespace AddUserLib
{
    public class NovaZakazkaEventArgs : EventArgs
    {
        private readonly string _cisloKarty = "";
        private readonly string _jmeno = "";
        private readonly string _prijmeni = "";
        private readonly string _cisloOp = "";
        private readonly string _telCislo = "";
        private readonly int _cenaCelkem = 0;
        private readonly List<NovyZbozi> _seznamZbozi;

        public NovaZakazkaEventArgs(string cisloKarty, string jmeno, string prijmeni,
                                        string cisloOP, string telCislo, List<NovyZbozi> seznamZbozi, int cenaCelkem)
        {
            _cisloKarty = cisloKarty;
            _jmeno = jmeno;
            _prijmeni = prijmeni;
            _cisloOp = cisloOP;
            _telCislo = telCislo;
            _seznamZbozi = seznamZbozi;
            _cenaCelkem = cenaCelkem;
        }

        public void SaveToDb(Tools.DB database, string table)
        {
            /* nahrazen LINQ vyraz
            foreach (NovyZbozi zbozi in SeznamZbozi)
            {
                Dictionary<string, string> row = new Dictionary<string, string>();
                row.Add("JIScislo", CisloKarty);
                row.Add("jmeno", Jmeno);
                row.Add("prijmeni", Prijmeni);
                row.Add("OP", CisloOP);
                 row.Add("zboziID", zbozi.CarovyKod);
                 row.Add("zboziNazev", zbozi.Nazev);
                 row.Add("cena", zbozi.Cena);
                 row.Add("do", zbozi.KeDni.Date.ToString("yyyy-MM-dd hh:mm:ss"));
                 row.Add("od", zbozi.OdDne.Date.ToString("yyyy-MM-dd hh:mm:ss"));
                 row.Add("idZakaznik", Jmeno+Prijmeni+OsobniCislo+CisloKarty+CisloOP);
                 database.AddRow(table, row);
            }*/

            // prosim pridat TelCislo do tabulky Zakaznici.telCislo
            foreach (Dictionary<string, string> row in SeznamZbozi.Select(zbozi => new Dictionary<string, string>
                {
                    {"JIScislo", CisloKarty},
                    {"jmeno", Jmeno},
                    {"prijmeni", Prijmeni},
                    {"OP", CisloOP},
                    {"zboziID", zbozi.CarovyKod},
                    {"zboziNazev", zbozi.Nazev},
                    {"cena", zbozi.Cena},
                    {"do", zbozi.KeDni.Date.ToString("yyyy-MM-dd hh:mm:ss")},
                    {"od", zbozi.OdDne.Date.ToString("yyyy-MM-dd hh:mm:ss")},
                    {"idZakaznik", Jmeno + Prijmeni + CisloKarty + CisloOP}
                }))
            {
                database.AddRow(table, row);
            }
        }

        // Properties
        public string CisloKarty
        {
            get { return _cisloKarty; }
        }

        public string Jmeno
        {
            get { return _jmeno; }
        }

        public string Prijmeni
        {
            get { return _prijmeni; }
        }

        public string CisloOP
        {
            get { return _cisloOp; }
        }

        public string TelCislo
        {
            get { return _telCislo; }
        }

        public List<NovyZbozi> SeznamZbozi
        {
            get { return _seznamZbozi; }
        }

        public int CenaCelkem
        {
            get { return _cenaCelkem; }
        }
    }
}
